package operation;

import book.Book;
import book.BookList;

public class DelOperation implements IOperation{

    public void work(BookList booklist){
        System.out.println("删除图书");
        System.out.println("请输入你要删除的图书的名字：");
        String name = scanner.nextLine();
        int currentSize = booklist.getUsedSize();
        int index = 0;
        int i = 0;
        for(; i < currentSize; i++){
            Book book = booklist.getPos(i);
            if(name.equals(book.getName())){
                index = i;
                System.out.println("已找到，进行删除");
                break;
            }
        }
        if(i >= currentSize){
            System.out.println("没有你要删除的书！");
            return;
        }
        for(int j = index; j < currentSize-1;j++){
            Book book = booklist.getPos(j+1);
            booklist.setBook(j,book);
        }
        booklist.setBook(currentSize, null);

        booklist.setUsedSize(currentSize-1);
        System.out.println("删除成功！");


    }
}
